home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / interp / num.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  2.9 KB  |  98 lines  |  [TEXT/ttxt]

  1. /**********************************************************************\
  2. *
  3. *  Copyright (c) 1994  Carnegie Mellon University
  4. *  All rights reserved.
  5. *  
  6. *  Use and copying of this software and preparation of derivative
  7. *  works based on this software are permitted, including commercial
  8. *  use, provided that the following conditions are observed:
  9. *  
  10. *  1. This copyright notice must be retained in full on any copies
  11. *     and on appropriate parts of any derivative works.
  12. *  2. Documentation (paper or online) accompanying any system that
  13. *     incorporates this software, or any part of it, must acknowledge
  14. *     the contribution of the Gwydion Project at Carnegie Mellon
  15. *     University.
  16. *  
  17. *  This software is made available "as is".  Neither the authors nor
  18. *  Carnegie Mellon University make any warranty about the software,
  19. *  its performance, or its conformity to any specification.
  20. *  
  21. *  Bug reports, questions, comments, and suggestions should be sent by
  22. *  E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  23. *
  24. ***********************************************************************
  25. *
  26. * $Header: num.h,v 1.6 94/11/03 22:19:27 wlott Exp $
  27. *
  28. \**********************************************************************/
  29.  
  30. #define obj_is_fixnum(o) (!obj_is_ptr(o))
  31. #define fixnum_value(o) (((long)(o))>>1)
  32. #define make_fixnum(i) ((obj_t)(((long)(i))<<1))
  33. #define MAX_FIXNUM ((obj_t)((((unsigned long)~0)<<2)>>1))
  34. #define MIN_FIXNUM ((obj_t)~(((unsigned long)~0)>>1))
  35.  
  36. typedef unsigned char digit_t;
  37.  
  38. struct bignum {
  39.     obj_t class;
  40.     int length;
  41.     digit_t digits[1];
  42. };
  43.  
  44. #define BIGNUM(o) obj_ptr(struct bignum *, o)
  45.  
  46. extern obj_t make_bignum(long value);
  47. #define as_bignum(i) (obj_is_fixnum(i)?make_bignum(fixnum_value(i)):(i))
  48. extern long bignum_value(obj_t x);
  49. extern int compare_bignums(obj_t x, obj_t y);
  50. extern obj_t add_bignums(obj_t x, obj_t y);
  51. extern obj_t subtract_bignums(obj_t x, obj_t y);
  52. extern obj_t negate_bignum(obj_t x);
  53. extern obj_t multiple_bignums(obj_t x, obj_t y);
  54.  
  55. extern void print_bignum(obj_t bignum, int radix);
  56.  
  57.  
  58. struct ratio {
  59.     obj_t class;
  60.     obj_t numerator;
  61.     obj_t denominator;
  62. };
  63.  
  64. #define RATIO(o) obj_ptr(struct ratio *, o)
  65.  
  66. struct single_float {
  67.     obj_t class;
  68.     float value;
  69. };
  70.  
  71. extern obj_t make_single(float value);
  72. #define single_value(x) (obj_ptr(struct single_float *, x)->value)
  73.  
  74. struct double_float {
  75.     obj_t class;
  76.     double value;
  77. };
  78.  
  79. extern obj_t make_double(double value);
  80. #define double_value(x) (obj_ptr(struct double_float *, x)->value)
  81.  
  82. struct extended_float {
  83.     obj_t class;
  84.     long double value;
  85. };
  86.  
  87. extern obj_t make_extended(long double value);
  88. #define extended_value(x) (obj_ptr(struct extended_float *, x)->value)
  89.  
  90. extern obj_t obj_IntegerClass;
  91. extern obj_t obj_FixnumClass;
  92. extern obj_t obj_BignumClass;
  93. extern obj_t obj_SingleFloatClass;     /* table.c needs the floats */
  94. extern obj_t obj_DoubleFloatClass;
  95. extern obj_t obj_ExtendedFloatClass;
  96.  
  97. extern boolean idp(obj_t x, obj_t y);
  98.